package com.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

@Service
public class RedisService {

    @Autowired
    private RedisTemplate  redisTemplate;


    public Set myfriend(Set set1, Set set2)
    {


        //set转为list
        List list1 = new ArrayList(set1);
        List list2 = new ArrayList(set2);
        //把list转数组，并添加到redis的set集合
        redisTemplate.boundSetOps("set1").add(list1.toArray());
        redisTemplate.boundSetOps("set2").add(list2.toArray());

        Set result = redisTemplate.opsForSet().intersect("set1","set2");
        return result;
    }


}












